﻿using OperationPlugins.Validators.DataAnnotations;

namespace TimeProject.WebSite.ViewModels
{
    [UsePluginValidators]
    public abstract class ViewModelBase
    {
        /// <summary>
        /// Contains all messages.
        /// </summary>
        public MessageContainer Messages { get; set; }

        public bool LazyLoading { get; set; }

        /// <summary>
        /// Redirect after post?
        /// </summary>
        public bool redirect { get; set; }

        /// <summary>
        /// Redirect url.
        /// </summary>
        public string url { get; set; }

        public bool isDirty { get; set; }

        protected ViewModelBase()
        {
            Initialize();
        }

        /// <summary>
        /// Redirect browser to URL.
        /// </summary>
        /// <param name="url">URL</param>
        public void RedirectTo(string url)
        {
            this.redirect = true;
            this.url = url;
        }

        public void Initialize()
        {
            OnInitialize();
        }

        protected virtual void OnInitialize()
        {
            Messages = new MessageContainer();
            isDirty = false;
        }

    }
}